/**
  * @Description: WoShop商城
  * @Author: 梧桐
  * @Copyright: 武汉一一零七科技有限公司©版权所有
  * @Link: www.s1107.com
  * @Contact: QQ:2487937004
  */
<template>
  <view >
    <view class="inputWrap">
      <u-input class="input"  v-model="phone" placeholder="请填写联系电话" maxlength="11" :border="true" border-color="#eee"/>
        <view class="u-flex u-row-between u-col-center">
          <u-input class="input"  v-model="code" placeholder="请输入验证码"   maxlength="6" :border="true" border-color="#eee" />
            <text class="sendcoder" @click="editPwdSms"  >{{clickText}}</text>
        </view>
        <u-input class="input" type="password" v-model="newpwd" placeholder="请输入新密码"  maxlength="11" :border="true" border-color="#eee" />
        <u-input class="input" type="password"  v-model="newpwd2" placeholder="请确认密码"  maxlength="11" :border="true" border-color="#eee"/>
   
        <u-button type="error" mode="plain" style="margin-top: 40upx;" @click="confirmClick">确认修改</u-button>
   
    </view>
  </view>
</template>

<script>
let courr = 60;
let setId = null;
export default {
 
  data() {
    return {
      phone: "",
      newpwd: "",
      newpwd2: "",
      code: "",
      clickText: ""
    };
  },
  onLoad() {
    this.gethuoquphone();
    uni.setNavigationBarTitle({
      title: '修改登录密码'
    });
    this.clickText = '获取验证码'
  },
  copmputed:{
    returnPwd(){
      return this.newpwd===this.newpwd2
    }
  },

  methods: {
    confirmClick() {
      if (this.code == "") {
        this.$toast('请输入验证码');
        return false;
      }
      if (this.newpwd == "") {
        this.$toast('请输入密码');
        return false;
      }
      if (this.newpwd !== this.newpwd2) {
        return this.$toast('两次输入的密码不一致');
        
      }

      this.$http
        .geteditpwd({
          code: this.code,
          phone: this.phone,
          new_pwd: this.newpwd
        })
        .then(res => {
          console.log(this.code);
          if (res.status == 200) {
            this.$toast(res.mess);
            uni.clearStorage();
            setTimeout(() => {
              uni.reLaunch({
                url: "/pagesB/login/login"
              });
            }, 1500);
          }
     
        });
    },
    editPwdSms() {
      if (this.phone.length != 11) {
        this.$toast('请输入正确的手机号');
        return false;
      }
      // if (setId) {
      //   // 禁止重复发送
      //   return false;
      // }
      this.$http.editPwdSms({ phone: this.phone }).then(res => {
        if (res.status == 200) {
          this.$toast(res.mess);
          setId = setInterval(() => {
            courr--;
            if (courr == 0) {
              courr = 60;
              clearInterval(setId);
              this.clickText = '重新获取';

              return false;
            }
            this.clickText = courr + "s";
          }, 1000);
        }
      });
    },
    gethuoquphone() {
      this.$http.gethuoquphone().then(res => {
        if (res.status == 200) {
          this.phone = res.data.phone;
        }
      });
    }
  }
};
</script>

<style scoped>
.inputWrap{
  
  background-color: #fff;
  padding: 30upx;
}
.input{
  height:80upx;
  margin: 20upx 0;
}
.sendcoder{
  font-size: 24upx;
  color: #ffa468;
  margin-left: 20upx;
}
</style>
